﻿<cfsilent>
	<cfsetting requesttimeout="60" />
	<cfscript>
	
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		zipper = getProperty("serviceFactory").getBean("tagZipHelper");
		filer = getProperty("serviceFactory").getBean("tagFileHelper");

		picSuccess = 0;
		picFailure = 0;

		response = structNew();
		structInsert(response, "success", false, true);

		studentIds = event.getArg("StudentIDs");
		studentArray = listToArray( studentIds, "," );
		
		zipUUID = event.getArg("UUID");
		
		zipFile = getProperty("cdnAssetsPath") & "/tmp/stuPictureCET/" & zipUUID & ".zip";
		zipDir = getProperty("cdnAssetsPath") & "/tmp/stuPictureCET/" & zipUUID;
		
		if ( not directoryExists( zipDir ) ) {
			directoryCreate( zipDir );
		}
		
		/* 复制文件到指定目录 */
		for ( stuId in studentArray ) {
			
			profilePicture = getProperty("cdnAssetsPath") & "/student/profile/" & left( stuId, 4 ) & "/" & stuId & ".jpg";
			
			if ( fileExists(profilePicture) ) {
				
				filer.copy( profilePicture, zipDir & "/" & stuId & ".jpg" );
				
				picSuccess++;
			}
			else {
				picFailure++;
			}
			
		}
		
		if ( picSuccess ) {
			/* 按目录打包文件 */
			zipper.addDirectory( zipfile=zipFile, source=zipDir, filter="*.jpg" );
		}
		
		/* 删除目录及所有文件 */
		directoryDelete( zipDir, true );
		
		structInsert(response, "operation", "本次处理 "& arrayLen(studentArray) &" 张图片, 成功追加电子照片 "& picSuccess &" 张, 无效图片 "& picFailure &" 张", true);
		structInsert(response, "success", true, true);

	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>